package com.uml.umlwork.controller;

import com.uml.umlwork.config.annotation.UserLoginToken;
import com.uml.umlwork.dto.classs.AddClassDTO;
import com.uml.umlwork.service.ClassService;
import com.uml.umlwork.utils.PageResult;
import com.uml.umlwork.utils.SystemMsgJsonResponse;
import com.uml.umlwork.vo.clazz.ClassTeacherVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
/**
 * @author Siki
 * @date 2021/1/7
 */
@Api(tags = "培训班相关模块 - api")
@RequestMapping("/api/v1/umlwork/class")
@RestController
@UserLoginToken
public class ClassController {

    private final ClassService classService;

    public ClassController(ClassService classService){
        this.classService = classService;
    }


    @GetMapping("/getClassByTeacherId")
    @ApiOperation(value = "[培训师]-查询培训师负责培训班级接口",httpMethod = "GET")
    public SystemMsgJsonResponse getClassByTeacherId(
            @RequestParam(value = "current",defaultValue = "1") Long current,
            @RequestParam(value = "size",defaultValue = "10") Long size,
            @RequestParam("teacherId") Integer teacherId){
        PageResult<ClassTeacherVO> classes = classService.getClassByTeacherId(current,size,teacherId);
        return SystemMsgJsonResponse.success(classes);
    }

    @PostMapping("/createClass")
    @ApiOperation(value = "开设培训班接口")
    public SystemMsgJsonResponse createClass(@RequestBody @Validated AddClassDTO dto){
        classService.createClass(dto);
        return SystemMsgJsonResponse.success();
    }

    @GetMapping("/updateClass")
    @ApiOperation(value = "修改培训班状态",httpMethod = "GET")
    public SystemMsgJsonResponse updateClass(@RequestParam("classId") Integer id,
                                            @RequestParam("open") Integer open){
        classService.updateClassStatus(id,open);
        return SystemMsgJsonResponse.success();
    }

    @PostMapping("/getMyClass")
    @ApiOperation(value = "查询自己的培训班",httpMethod = "POST")
    public SystemMsgJsonResponse getMyClass(@RequestAttribute("userId") String id){
        return SystemMsgJsonResponse.success(classService.getMyClass(id));
    }
}
